package com.miplus.ccrm.workflow.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.ServiceException;
import com.miplus.ccrm.workflow.mapper.WorkflowRecycleMapper;
import com.miplus.ccrm.workflow.model.dto.recycle.*;
import com.miplus.ccrm.workflow.model.po.Workflow;
import com.miplus.ccrm.workflow.model.po.WorkflowRecycle;
import com.miplus.ccrm.workflow.model.vo.WorkflowRecycleVO;
import com.miplus.ccrm.workflow.service.WorkflowRecycleService;
import com.miplus.ccrm.workflow.service.WorkflowService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author feixiang
* @description 针对表【workflow_recycle(话术回收站表)】的数据库操作Service实现
* @createDate 2025-11-01 17:41:37
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class WorkflowRecycleServiceImpl extends MPJBaseServiceImpl<WorkflowRecycleMapper, WorkflowRecycle>
    implements WorkflowRecycleService {
    @Resource
    private WorkflowService workflowService;

    @Override
    public IPage<WorkflowRecycleVO> getRecyclePage(RecycleQueryDTO dto) {
        MPJLambdaWrapper<WorkflowRecycle> wrapper = new MPJLambdaWrapper<WorkflowRecycle>()
                .selectAll(WorkflowRecycle.class)
                .select("w.name as workflowName", "w.description", "w.category_id as categoryId",
                        "w.industry_type as industryType", "w.tags", "w.icon", "w.created_by as createdBy", "w.create_time as createTime")
                .leftJoin("workflow w on t.workflow_id = w.id");
        return selectJoinListPage(new Page<>(dto.getPageNum(), dto.getPageSize()), WorkflowRecycleVO.class, wrapper);
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public CmdResVo restoreWorkflow(RestoreWorkflowDTO dto, String userId) {
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CmdResVo permanentDelete(PermanentDeleteDTO dto, String userId) {
        return new CmdResVo(20001, "清理成功");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CmdResVo clearRecycle(ClearRecycleDTO dto, String userId) {
        return new CmdResVo(20001, "清理成功");
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CmdResVo cleanExpiredData(String userId) {
        return new CmdResVo(20001, "清理成功");
    }

    @Override
    public WorkflowRecycleVO getRecycleDetail(String recycleId) {
        return null;
    }
}



